////////////////////////////////////////////////////////////////////////////////////////////////////
/// Copyright (c) 2009 - 2010 RacoonStudios
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this
/// software and associated documentation files (the "Software"), to deal in the Software
/// without restriction, including without limitation the rights to use, copy, modify, merge,
/// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
/// to whom the Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all copies or
/// substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
/// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
/// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
/// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
/// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
/// DEALINGS IN THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once
#ifndef streamreader_h__
#define streamreader_h__

#include "core/referencecount.h"
#include "core/smartptr.h"
#include "iosystem/stream.h"

namespace IO
{
	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// \class	StreamReader
	///
	/// \brief	This class is an abstract type for any reading access for a stream.
	///			This one is the base class for all classes that needs access for reading
	///			a stream.
	///
	/// \author	khaos
	/// \date	05.01.2010
	////////////////////////////////////////////////////////////////////////////////////////////////////
	class StreamReader : public Core::ReferenceCount
	{
		RE_DeclareClass(IO::StreamReader);

	public:

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// \fn	public: StreamReader()
		///
		/// \brief	Constructor. 
		///
		/// \author	khaos
		/// \date	05.01.2010
		////////////////////////////////////////////////////////////////////////////////////////////////////
		StreamReader();

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// \fn	virtual ~StreamReader()
		///
		/// \brief	Finaliser. 
		///
		/// \author	khaos
		/// \date	05.01.2010
		////////////////////////////////////////////////////////////////////////////////////////////////////
		virtual ~StreamReader();




		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// \fn	void SetStream(const SmrtPtr<Stream> & strm)
		///
		/// \brief	Sets a stream. 
		///
		/// \author	khaos
		/// \date	05.01.2010
		///
		/// \param	[in]	strm	The strm. 
		////////////////////////////////////////////////////////////////////////////////////////////////////
		void SetStream(const SmrtPtr<Stream> & strm);

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// \fn	const SmrtPtr<Stream> & GetStream() const
		///
		/// \brief	Returns the stream.
		///
		/// \author	khaos
		/// \date	05.01.2010
		///
		/// \return	The stream. 
		////////////////////////////////////////////////////////////////////////////////////////////////////
		const SmrtPtr<Stream> & GetStream() const;

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// \fn	bool ValidStream() const
		///
		/// \brief	Returns true if a stream is set. 
		///
		/// \author	khaos
		/// \date	05.01.2010
		///
		/// \return	True if stream is set, otherwise false. 
		////////////////////////////////////////////////////////////////////////////////////////////////////
		bool ValidStream() const;

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// \fn	bool Eof() const
		///
		/// \brief	Returns true if the EOF is reached.
		///
		/// \author	khaos
		/// \date	05.01.2010
		///
		/// \return	True if EOF is reached, otherwise false.
		////////////////////////////////////////////////////////////////////////////////////////////////////
		bool Eof() const;

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// \fn	bool IsOpen() const
		///
		/// \brief	Returns true if the stream is opened.
		///
		/// \author	khaos
		/// \date	05.01.2010
		///
		/// \return	True if the stream is opened, otherwise false.
		////////////////////////////////////////////////////////////////////////////////////////////////////
		bool IsOpen() const;




		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// \fn	virtual bool Open()
		///
		/// \brief	Opens the stream for reading.
		///
		/// \author	khaos
		/// \date	05.01.2010
		///
		/// \return	True if the stream can be opened, otherwise false.
		////////////////////////////////////////////////////////////////////////////////////////////////////
		virtual bool Open();

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// \fn	virtual void Close()
		///
		/// \brief	Closes the stream.
		///
		/// \author	khaos
		/// \date	05.01.2010
		////////////////////////////////////////////////////////////////////////////////////////////////////
		virtual void Close();

	protected:

		SmrtPtr<Stream> m_stream;

		bool m_isOpen;
		bool m_streamWasOpen;

	private:

	};

}

#endif // streamreader_h__